<template>
	<view v-if="info.couponsName" class="box" :style="theme">
		<!-- 优惠券信息 -->
		<view class="box_q">
			<view class="box_piao_item">
				<view class="box_piao_item_left" :class="info.remaining > 0?'':'hui'">
					<text>{{info.couponsType == '1' ? '代金券' : '折扣券'}}</text>
					<text v-if="info.couponsType == '1'">{{info.discountNum}}元</text>
					<text v-if="info.couponsType == '0'">{{info.discountNum}}折</text></text>
					<view class="box_piao_item_left_a"></view>
					<view class="box_piao_item_left_b"></view>
				</view>
				<view class="box_piao_item_right">
					<text>{{info.couponsName}}</text>
					<text v-if="info.couponsType == 0" class="js limit-2-line">订单满{{info.miniNum}}享{{info.discountNum}}折</text>
					<text v-else class="js limit-2-line">订单满{{info.miniNum}}减{{info.discountNum}}元</text>
				</view>
			</view>
		</view>
		<!-- 使用条件 -->
		<view class="box_z">
			<view v-if="info.validityDays" class="box_z_item">
				<text>适用时间</text>
				<text>领取{{info.validityDays}}天内有效</text>
			</view>
			<view class="box_z_item">
				<text>适用时间段</text>
				<text>{{info.useTimeInfo}}</text>
			</view>
			<view class="box_z_item">
				<text>适用项目</text>
				<text>{{info.useProject}}</text>
			</view>
			<view v-if="info.useDes" class="box_z_item">
				<text>适用说明</text>
				<text>{{info.useDes}}</text>
			</view>
		</view>
		<!-- 占位 -->
		<view v-if="type!=2" class="box_zw"></view>
		<!-- 底部领取 -->
		<view v-if="type!=2" class="box_b">
			<view :class="is == 0?'box_b_button':'box_b_buttons'" @click="$noMultipleClicks(submit)">立即领取</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				noClick: true,
				id: '',
				type: 1,
				is: 1,
				info: {}
			}
		},
		onLoad(ops) {
			uni.showShareMenu({
				withShareTicket: true,
				menus: ["shareAppMessage", "shareTimeline"]
			})
			this.id = ops.id
			this.type = ops.type || 1
		},
		onShow() {
		   setTimeout(()=> {
			   this.getDetail()
		   }, 300)	
		},
		methods: {
			getDetail() {
				let that = this
				this.$app.ajax({
					data: {
						param: {
							couponsId: this.id,
							isMult: '1'
						}
					},
					api: this.$api.couponDetails()
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.info = res.record
						if (this.type != 2) {
							that.$app.ajax({
								data: {
									param: {
										couponsId: that.id
									}
								},
								api: that.$api.judgeCoupons()
							}).then((resb) => {
								if (resb.errorCode === '000000') {
									that.is = resb.record.flage || 1
								}
							}).catch(() => {})
						}
					} else {
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 500)
					}
				}).catch(() => {})
			},
			submit() {
				if (this.is == '1') {
					this.$app.showToast('当前优惠券不可领取')
					return false
				}
				this.$app.ajax({
					data: {
						userId: this.userInfo.id,
						param: {
							couponsId: this.id
						}
					},
					api: this.$api.receiveCoupons()
				}).then((res) => {
					if (res.errorCode == '000000') {
						this.$app.showToast('领取成功')
						this.getDetail()
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 1000)
					}
				}).catch(() => {})
			},
		},
	}
</script>
<style>
	page {
		background-color: #fff;
	}
</style>
<style lang="scss" scoped>
	.box_q {
		padding: 30rpx;
		background-color: #F7F7F7;
		box-sizing: border-box;
		background: $bjColor;
		display: flex;
		flex-direction: column;
	}

	.box_q_wz {
		width: 100%;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		font-size: 36rpx;
		font-weight: 500;
		color: #222222;
	}

	.box_q_dz {
		display: flex;
		align-items: center;
		margin-top: 26rpx;
		image {
			width: 28rpx;
			height: 28rpx;
		}
		text {
			font-size: 24rpx;
			font-weight: 400;
			color: #666666;
			margin-left: 4rpx;
		}
	}

	.box_piao_item {
		height: 180rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #ffffff;
		border-radius: 15rpx;
		overflow: hidden;
		// margin-top: 32rpx;
	}

	.box_piao_item_left {
		width: 180rpx;
		height: 180rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		position: relative;
		background: $phb;
		box-shadow: inset 0px 2rpx 4rpx 0px rgba(255, 255, 255, 0.47);
		color: #FFFFFF;
		&.hui {
			color: #888888;
			background: #DDDDDD;
		}
	}

	.box_piao_item_left_a {
		position: absolute;
		right: -15rpx;
		top: -15rpx;
		width: 30rpx;
		height: 30rpx;
		border-radius: 50%;
		background: $bjColor;
	}

	.box_piao_item_left_b {
		position: absolute;
		right: -15rpx;
		bottom: -15rpx;
		width: 30rpx;
		height: 30rpx;
		border-radius: 50%;
		background: $bjColor;
	}

	.box_piao_item_left text:nth-child(1) {
		font-size: 24rpx;
		font-weight: 400;
	}

	.box_piao_item_left text:nth-child(2) {
		font-size: 44rpx;
		font-weight: 500;
		margin: 5rpx 0;
	}

	.box_piao_item_left text:nth-child(2) text {
		font-size: 24rpx;
		font-weight: 500;
	}

	.box_piao_item_right {
		flex: 1;
		height: 100%;
		padding: 20rpx 30rpx;
		box-sizing: border-box;

		text {
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;

			&:nth-child(1) {
				font-size: 30rpx;
				font-weight: 500;
				color: #222222;
			}

			&:nth-child(2) {
				font-size: 24rpx;
				font-weight: 400;
				color: #333333;
				margin: 10rpx 0;
			}

			&:nth-child(3) {
				font-size: 24rpx;
				font-weight: 400;
				color: #666666;
			}
		}
	}


	.box_z {
		padding: 30rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;

		.box_z_item {
			display: flex;
			flex-direction: column;
			padding-bottom: 30rpx;
			margin-top: 30rpx;
			border-bottom: 1rpx solid #E5E5E5;

			&:first-child {
				margin-top: 0;
			}

			&:last-child {
				border: none;
			}

			text {
				font-size: 28rpx;
				font-weight: 500;
				color: #222222;

				&:nth-child(2) {
					font-size: 26rpx;
					font-weight: 400;
					color: #666666;
					margin-top: 24rpx;
				}
			}
		}
	}

	.box_zw {
		height: 180rpx;
	}

	.box_b {
		width: 100%;
		height: 160rpx;
		padding: 30rpx;
		box-sizing: border-box;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
	}

	.box_b_button {
		height: 100rpx;
		background: $color;
		border-radius: 50rpx;
		font-size: 30rpx;
		font-weight: 500;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.box_b_buttons {
		height: 100rpx;
		background: #dddddd;
		border-radius: 50rpx;
		font-size: 30rpx;
		font-weight: 500;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>